﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace QuDao.Api.Controllers
{
    /// <summary>
    /// 商品API
    /// </summary>
    //[ApiExplorerSettings(IgnoreApi = true)]
    public class GoodsController : ApiControllerBase
    {
        /// <summary>
        /// 获取商品详情
        /// </summary>
        /// <param name="id">商品ID</param>
        [HttpGet]
        [AllowAnonymous]
        public GoodsDetailsDto GetDetails(int id)
        {
            return GoodsBO.Instance.GetDetails(id);
        }

        /// <summary>
        /// 获取租户在售商品列表
        /// </summary>
        /// <param name="tid">租户ID</param>
        /// <param name="ut">用户类型：A|B|C</param>
        /// <param name="categoryID">商品类别ID</param>
        /// <param name="pageIndex">页索引，从1开始</param>
        /// <param name="pageSize">每页记录数，默认10</param>
        [HttpGet]
        [AllowAnonymous]
        public IEnumerable<GoodsDto> GetList([FromHeader] int tid, [FromHeader] string ut, int categoryID, int pageIndex = 1, int pageSize = 10)
        {
            return GoodsBO.Instance.GetList(tid, ut, categoryID, pageIndex, pageSize);
        }

        /// <summary>
        /// 同步商品销售数据
        /// </summary>
        /// <param name="tid">租户ID</param>
        /// <param name="beginDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public string SyncGoodsSalesData(int tid, DateTime beginDate, DateTime endDate)
        {
            GoodsSalesBO.Instance.SyncOrderData(tid, beginDate, endDate);
            return "OK";
        }
    }
}
